home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / basic / vect.zip / VECT.ASM < prev    next >
Assembly Source File  |  1992-06-04  |  25KB  |  1,486 lines

  1. ;3-D Rotation & Perspective
  2. ;By Rich Geldreich
  3. ;May 27th, 1992
  4.  
  5. ;TASM v2.00 source code follows... set tab stops to 8, don't insert spaces
  6.  
  7. ;Also see 3dexp2.bas from which this code was derived from.
  8.  
  9. ;The following keys may be used in the program:(turn NumLock on!)
  10.  
  11. ;spacebar.................stops all rotation
  12. ;"r" key..................resets all three angles
  13. ;"n" & "m" key............controls the third angle
  14. ;arrow keys...............controls the other two angles
  15. ;numeric keypad...........controls your position relative to the stars
  16. ;escape key...............quits
  17.  
  18. ideal
  19. model small
  20. dosseg
  21. stack 1024
  22.  
  23. NumPoints = 765
  24. P_Scaler = 4000
  25. Z_Plane_Threshold = 130
  26.  
  27. ;-------------------------------------------------------------------------------
  28.  
  29. dataseg 
  30. even
  31.  
  32. ;used for setting points...
  33. line_table:
  34. b=0
  35. rept 200
  36.     dw b*320
  37.     b=b+1
  38. endm
  39.  
  40. points_to_rotate:
  41. include "pnt.asm"
  42.  
  43.     even
  44. ;simple bitmapped character font
  45. characters:
  46.     db 01110000b
  47.     db 10011000b
  48.     db 10011000b
  49.     db 10101000b
  50.     db 11001000b
  51.     db 11001000b
  52.     db 01110000b
  53.     db 00000000b
  54.          
  55.     db 00100000b
  56.     db 01100000b
  57.     db 10100000b
  58.     db 00100000b
  59.     db 00100000b
  60.     db 00100000b
  61.     db 11111000b
  62.     db 00000000b
  63.     
  64.     db 01110000b
  65.     db 10001000b
  66.     db 00010000b
  67.     db 00100000b
  68.     db 01000000b
  69.     db 10000000b
  70.     db 11111000b
  71.     db 00000000b
  72.     
  73.     db 01110000b
  74.     db 10001000b
  75.     db 00001000b
  76.     db 00110000b
  77.     db 00001000b
  78.     db 10001000b
  79.     db 01110000b
  80.     db 00000000b
  81.                 
  82.     db 10001000b
  83.     db 10001000b
  84.     db 10001000b
  85.     db 11111000b
  86.     db 00001000b
  87.     db 00001000b
  88.     db 00001000b
  89.     db 00000000b
  90.     
  91.     db 11111000b
  92.     db 10000000b
  93.     db 10000000b
  94.     db 11110000b
  95.     db 00001000b
  96.     db 10001000b
  97.     db 01110000b
  98.     db 00000000b
  99.     
  100.     db 01110000b
  101.     db 10001000b
  102.     db 10000000b
  103.     db 11110000b
  104.     db 10001000b
  105.     db 10001000b
  106.     db 01110000b
  107.     db 00000000b
  108.     
  109.     db 11111000b
  110.     db 00001000b
  111.     db 00010000b
  112.     db 00100000b
  113.     db 01000000b
  114.     db 10000000b
  115.     db 10000000b
  116.     db 00000000b
  117.     
  118.     db 01110000b
  119.     db 10001000b
  120.     db 10001000b
  121.     db 01110000b
  122.     db 10001000b
  123.     db 10001000b
  124.     db 01110000b
  125.     db 00000000b
  126.     
  127.     db 01110000b
  128.     db 10001000b
  129.     db 10001000b
  130.     db 01111000b
  131.     db 00001000b
  132.     db 10001000b
  133.     db 01110000b
  134.     db 00000000b
  135. minus_sign:
  136.     db 00000000b
  137.     db 00000000b
  138.     db 00000000b
  139.     db 01111110b
  140.     db 00000000b
  141.     db 00000000b
  142.     db 00000000b
  143.     db 00000000b
  144. space:
  145.     db 00000000b
  146.     db 00000000b
  147.     db 00000000b
  148.     db 00000000b
  149.     db 00000000b
  150.     db 00000000b
  151.     db 00000000b
  152.     db 00000000b
  153.  
  154. letters:
  155.     db 00100000b
  156.     db 01010000b
  157.     db 10001000b
  158.     db 11111000b
  159.     db 10001000b
  160.     db 10001000b
  161.     db 10001000b
  162.     db 00000000b
  163.     
  164.     db 11110000b
  165.     db 10001000b
  166.     db 10001000b
  167.     db 11110000b
  168.     db 10001000b
  169.     db 10001000b
  170.     db 11110000b
  171.     db 00000000b
  172.     
  173.     db 01110000b
  174.     db 10001000b
  175.     db 10000000b
  176.     db 10000000b
  177.     db 10000000b
  178.     db 10001000b
  179.     db 01110000b
  180.     db 00000000b
  181.     
  182.     db 11110000b
  183.     db 10001000b
  184.     db 10001000b
  185.     db 10001000b
  186.     db 10001000b
  187.     db 10001000b
  188.     db 11110000b
  189.     db 00000000b
  190.  
  191.     db 11111000b
  192.     db 10000000b
  193.     db 10000000b
  194.     db 11110000b
  195.     db 10000000b
  196.     db 10000000b
  197.     db 11111000b
  198.     db 00000000b
  199.  
  200.     db 11111000b
  201.     db 10000000b
  202.     db 10000000b
  203.     db 11110000b
  204.     db 10000000b
  205.     db 10000000b
  206.     db 10000000b
  207.     db 00000000b
  208.           
  209.     db 01110000b
  210.     db 10001000b
  211.     db 10000000b
  212.     db 10111000b
  213.     db 10001000b
  214.     db 10001000b
  215.     db 01110000b
  216.     db 00000000b
  217.          
  218.     db 10001000b
  219.     db 10001000b
  220.     db 10001000b
  221.     db 11111000b
  222.     db 10001000b
  223.     db 10001000b
  224.     db 10001000b
  225.     db 00000000b
  226.  
  227.     db 11111000b
  228.     db 00100000b
  229.     db 00100000b
  230.     db 00100000b
  231.     db 00100000b
  232.     db 00100000b
  233.     db 11111000b
  234.     db 00000000b
  235.          
  236.     db 00001000b
  237.     db 00001000b
  238.     db 00001000b
  239.     db 00001000b
  240.     db 10001000b
  241.     db 10001000b
  242.     db 01110000b
  243.     db 00000000b
  244.  
  245.     db 10001000b
  246.     db 10010000b
  247.     db 10100000b
  248.     db 11000000b
  249.     db 10100000b
  250.     db 10010000b
  251.     db 10001000b
  252.     db 00000000b
  253.  
  254.     db 10000000b
  255.     db 10000000b
  256.     db 10000000b
  257.     db 10000000b
  258.     db 10000000b
  259.     db 10000000b
  260.     db 11111000b
  261.     db 00000000b
  262.  
  263.  
  264.     db 10001000b
  265.     db 11011000b
  266.     db 10101000b
  267.     db 10101000b
  268.     db 10001000b
  269.     db 10001000b
  270.     db 10001000b
  271.     db 00000000b
  272.  
  273.     db 10001000b
  274.     db 11001000b
  275.     db 10101000b
  276.     db 10011000b
  277.     db 10001000b
  278.     db 10001000b
  279.     db 10001000b
  280.     db 00000000b
  281.  
  282.     db 01110000b
  283.     db 10001000b
  284.     db 10001000b
  285.     db 10001000b
  286.     db 10001000b
  287.     db 10001000b
  288.     db 01110000b
  289.     db 00000000b
  290.     
  291.     db 11110000b
  292.     db 10001000b
  293.     db 10001000b
  294.     db 11110000b
  295.     db 10000000b
  296.     db 10000000b
  297.     db 10000000b
  298.     db 00000000b
  299.  
  300.     db 01110000b
  301.     db 10001000b
  302.     db 10001000b
  303.     db 10001000b
  304.     db 10101000b
  305.     db 10011000b
  306.     db 01110000b
  307.     db 00000000b
  308.  
  309.     db 11110000b
  310.     db 10001000b
  311.     db 10001000b
  312.     db 11110000b
  313.     db 10100000b
  314.     db 10010000b
  315.     db 10001000b
  316.     db 00000000b
  317.     
  318.     db 01110000b
  319.     db 10001000b
  320.     db 10000000b
  321.     db 01110000b
  322.     db 00001000b
  323.     db 10001000b
  324.     db 01110000b
  325.     db 00000000b
  326.  
  327.     db 11111000b
  328.     db 00100000b
  329.     db 00100000b
  330.     db 00100000b
  331.     db 00100000b
  332.     db 00100000b
  333.     db 00100000b
  334.     db 00000000b
  335.     
  336.     db 10001000b
  337.     db 10001000b
  338.     db 10001000b
  339.     db 10001000b
  340.     db 10001000b
  341.     db 10001000b
  342.     db 01110000b
  343.     db 00000000b
  344.     
  345.     db 10001000b
  346.     db 10001000b
  347.     db 10001000b
  348.     db 10001000b
  349.     db 10001000b
  350.     db 01010000b
  351.     db 00100000b
  352.     db 00000000b
  353.     
  354.     db 10001000b
  355.     db 10001000b
  356.     db 10001000b
  357.     db 10001000b
  358.     db 10101000b
  359.     db 10101000b
  360.     db 11011000b
  361.     db 00000000b
  362.     
  363.     db 10001000b
  364.     db 10001000b
  365.     db 01010000b
  366.     db 00100000b
  367.     db 01010000b
  368.     db 10001000b
  369.     db 10001000b
  370.     db 00000000b
  371.  
  372.     db 10001000b
  373.     db 10001000b
  374.     db 01010000b
  375.     db 00100000b
  376.     db 00100000b
  377.     db 00100000b
  378.     db 00100000b
  379.     db 00000000b
  380.     
  381.     db 11111000b
  382.     db 00001000b
  383.     db 00010000b
  384.     db 00100000b
  385.     db 01000000b
  386.     db 10000000b
  387.     db 11111000b
  388.     db 00000000b
  389.  
  390.  
  391.     even
  392. ;sine table; 360 values each entry multiplied by 16,384
  393.         
  394. sine_table:
  395.  
  396. dw  0, 285, 571, 857, 1142, 1427, 1712, 1996, 2280, 2563, 2845, 3126, 3406
  397. dw  3685, 3963, 4240, 4516, 4790, 5062, 5334, 5603, 5871, 6137, 6401, 6663
  398. dw  6924, 7182, 7438, 7691, 7943, 8192, 8438, 8682, 8923, 9161, 9397, 9630
  399. dw  9860, 10086, 10310, 10531, 10748, 10963, 11173, 11381, 11585, 11785
  400. dw  11982, 12175, 12365, 12550, 12732, 12910, 13084, 13254, 13420, 13582
  401. dw  13740, 13894, 14043, 14188, 14329, 14466, 14598, 14725, 14848, 14967
  402. dw  15081, 15190, 15295, 15395, 15491, 15582, 15668, 15749, 15825, 15897
  403. dw  15964, 16025, 16082, 16135, 16182, 16224, 16261, 16294, 16321, 16344
  404. dw  16361, 16374, 16381, 16384, 16381, 16374, 16361, 16344, 16321, 16294
  405. dw  16261, 16224, 16182, 16135, 16082, 16025, 15964, 15897, 15825, 15749
  406. dw  15668, 15582, 15491, 15395, 15295, 15190, 15081, 14967, 14848, 14725
  407. dw  14598, 14466, 14329, 14188, 14043, 13894, 13740, 13582, 13420, 13254
  408. dw  13084, 12910, 12732, 12550, 12365, 12175, 11982, 11785, 11585, 11381
  409. dw  11173, 10963, 10748, 10531, 10310, 10086, 9860, 9630, 9397, 9161, 8923
  410. dw  8682, 8438, 8191, 7943, 7691, 7438, 7182, 6924, 6663, 6401, 6137, 5871
  411. dw  5603, 5334, 5062, 4790, 4516, 4240, 3963, 3685, 3406, 3126, 2845, 2563
  412. dw  2280, 1996, 1712, 1427, 1142, 857, 571, 285, 0,-285,-571,-857,-1142
  413. dw -1427,-1712,-1996,-2280,-2563,-2845,-3126,-3406,-3685,-3963,-4240,-4516
  414. dw -4790,-5062,-5334,-5603,-5871,-6137,-6401,-6663,-6924,-7182,-7438,-7691
  415. dw -7943,-8192,-8438,-8682,-8923,-9161,-9397,-9630,-9860,-10086,-10310
  416. dw -10531,-10748,-10963,-11173,-11381,-11585,-11785,-11982,-12175,-12365
  417. dw -12550,-12732,-12910,-13084,-13254,-13420,-13582,-13740,-13894,-14043
  418. dw -14188,-14329,-14466,-14598,-14725,-14848,-14967,-15081,-15190,-15295
  419. dw -15395,-15491,-15582,-15668,-15749,-15825,-15897,-15964,-16025,-16082
  420. dw -16135,-16182,-16224,-16261,-16294,-16321,-16344,-16361,-16374,-16381
  421. dw -16384,-16381,-16374,-16361,-16344,-16321,-16294,-16261,-16224,-16182
  422. dw -16135,-16082,-16025,-15964,-15897,-15825,-15749,-15668,-15582,-15491
  423. dw -15395,-15295,-15190,-15081,-14967,-14848,-14725,-14598,-14466,-14329
  424. dw -14188,-14043,-13894,-13740,-13582,-13420,-13254,-13084,-12910,-12732
  425. dw -12550,-12365,-12175,-11982,-11785,-11585,-11381,-11173,-10963,-10748
  426. dw -10531,-10310,-10086,-9860,-9630,-9397,-9161,-8923,-8682,-8438,-8191
  427. dw -7943,-7691,-7438,-7182,-6924,-6663,-6401,-6137,-5871,-5603,-5334,-5062
  428. dw -4790,-4516,-4240,-3963,-3685,-3406,-3126,-2845,-2563,-2280,-1996,-1712
  429. dw -1427,-1142,-857,-571,-285, 0, 285, 571, 857, 1142, 1427, 1712, 1996
  430. dw  2280, 2563, 2845, 3126, 3406, 3685, 3963, 4240, 4516, 4790, 5062, 5334
  431. dw  5603, 5871, 6137, 6401, 6663, 6924, 7182, 7438, 7691, 7943, 8192, 8438
  432. dw  8682, 8923, 9161, 9397, 9630, 9860, 10086, 10310, 10531, 10748, 10963
  433. dw  11173, 11381, 11585, 11785, 11982, 12175, 12365, 12550, 12732, 12910
  434. dw  13084, 13254, 13420, 13582, 13740, 13894, 14043, 14188, 14329, 14466
  435. dw  14598, 14725, 14848, 14967, 15081, 15190, 15295, 15395, 15491, 15582
  436. dw  15668, 15749, 15825, 15897, 15964, 16025, 16082, 16135, 16182, 16224
  437. dw  16261, 16294, 16321, 16344, 16361, 16374, 16381, 16383, 16381, 16374
  438. dw  16361, 16344
  439.  
  440. even
  441. ;current angles of rotation
  442. angle_1     dw 0
  443. angle_2     dw 0
  444. angle_3     dw 0
  445. ;cosine and sine of each angle
  446. cos_1         dw 0
  447. sin_1         dw 0
  448.  
  449. cos_2         dw 0
  450. sin_2         dw 0
  451.  
  452. cos_3         dw 0
  453. sin_3         dw 0
  454. ;perspective variables...
  455. s_pos        dw -200
  456. m_pos        dw 0
  457. ;current origon
  458. origon_x    dw 0
  459. origon_y    dw 70
  460. origon_z    dw -1500
  461. ;added to each angle every frame...
  462. delta_1        dw 1
  463. delta_2        dw 1
  464. delta_3        dw 2
  465. ;added to the origon every frame....
  466. move_x        dw 0
  467. move_y        dw 0
  468. move_z        dw 0
  469. ;temporary variables for the rotate32 procedure
  470. Y1        dw 0
  471. X2        dw 0
  472. Y3        dw 0
  473. ;current coordinates of points being rotated
  474. Xo        dw 0
  475. Yo        dw 0
  476. Zo        dw 0
  477. ;highest & lowest Z coordinates used for intensity of each pixel
  478. lowest_z    dw 0
  479. highest_z    dw 0
  480. ;temporary variables used by rotate32
  481. source        dw 0
  482. dest        dw 0
  483. ;frames per second stuff
  484. frames        dw 0
  485. frames_sec    dw 0
  486. ;used for printing numbers
  487. number_buffer    dw 0,0,0,0,0,0
  488. ;buffer for the points to erase
  489. point_loc    dw offset point_buffer_2
  490. ;number of points left to rotate used by rotate32
  491. points_left    dw 0
  492.  
  493. ;my stupid title
  494. string_1:
  495.     db 9,0,'3D ROTATION AND PERSPECTIVE',0
  496.     db 12,1,'BY RICH GELDREICH 1992',0
  497.     db 6,9,'IF YOU HAVE ANY QUESTIONS OR IDEAS',0
  498.     db 12,11,'I CAN BE CONTACTED AT',0
  499.     db 16,13,'410 MARKET ST',0
  500.     db 11,15,'GLOUCESTER CITY NJ 08030',0
  501.     db 16,17,'609-742-8752',0
  502.     db 11,24,'PRESS ANY KEY TO BEGIN',0
  503.  
  504. ;each holds x,y,z coordinates        
  505. even
  506. point_buffer_1    dw NumPoints*3 dup(?)        ;for plotting
  507. point_buffer_2    dw NumPoints*3 dup(?)        ;for erasing
  508.  
  509. ;-------------------------------------------------------------------------------
  510.  
  511. codeseg
  512.     even
  513. start:
  514.     mov     ax, @data
  515.     mov    ds, ax
  516.     mov    es, ax
  517.     
  518.     cld
  519.     assume ds:@data,es:nothing,ss:nothing
  520.     
  521.     mov      ax, 013h
  522.     int    010h
  523.     call    print_title
  524.     call    set_palette
  525.  
  526. ;notice that I fool with the timer tick count in BIOS memory... not
  527. ;cool but it works!
  528.     
  529.     push    es
  530.     mov    ax, 040h
  531.     mov    es, ax
  532.     mov    [word es:06ch], 0
  533.     pop    es
  534.  
  535.      even
  536. @@main_loop:
  537. ;have we done enough frames for a good estimate of speed?
  538.     mov    ax, [ds:frames]
  539.     inc    ax
  540.     cmp    ax, 61
  541.     jne    @@notyet
  542.     push    es
  543. ;yup; get # clicks
  544.     mov    ax, 040h
  545.     mov    es, ax
  546.     xor    cx, cx
  547.     xchg    cx, [es:06ch]
  548.     pop    es
  549. ;multiply be 60*18 and then scale the answer by 10 
  550. ;so we have one decimal digit too
  551.     mov    ax, (60*18*10)
  552.     xor    dx, dx
  553.     and    cx, cx
  554. ;don't divide by zero(just in case...)
  555.     jnz    @@timable
  556.     xor    ax, ax
  557.     jmp    short @@notyet
  558.     even
  559. @@timable:
  560.     div    cx
  561.     mov    [ds:frames_sec], ax
  562.     xor    ax, ax
  563. @@notyet:
  564.     mov    [ds:frames], ax
  565. ;update user's origon        
  566.     mov    ax, [ds:move_x]
  567.     add    [ds:origon_x], ax
  568.     
  569.     mov    ax, [ds:move_y]
  570.     add    [ds:origon_y], ax
  571.     
  572.     mov    ax, [ds:move_z]
  573.     add    [ds:origon_z], ax
  574. ;update the angles of rotation    
  575.     mov    ax, [ds:angle_1]
  576.     add    ax, [ds:delta_1]
  577.     cmp    ax, 359
  578.     jng     @@05
  579.     xor    ax, ax
  580. @@05:
  581.     and    ax, ax
  582.     jnl    @@05a
  583.     mov    ax, 359
  584. @@05a:
  585.     mov    [ds:angle_1], ax
  586.  
  587.     mov    ax, [ds:angle_2]
  588.     add    ax, [ds:delta_2]
  589.     cmp    ax, 359
  590.     jng     @@06
  591.     xor    ax, ax
  592. @@06:
  593.     and    ax, ax
  594.     jnl    @@06a
  595.     mov    ax, 359
  596. @@06a:
  597.     mov    [ds:angle_2], ax
  598.                   
  599.     mov    ax, [ds:angle_3]
  600.     add    ax, [ds:delta_3]
  601.     cmp    ax, 359
  602.     jng     @@07
  603.     xor    ax, ax
  604. @@07:
  605.     and    ax, ax
  606.     jnl    @@07a
  607.     mov    ax, 359
  608. @@07a:
  609.     mov    [ds:angle_3], ax
  610.  
  611.     mov    ax, @data
  612.     mov    es, ax
  613. ;set the cosine and sine for each angle
  614.     call    set_angles
  615.  
  616. ;rotate the points    
  617.     mov     si, offset points_to_rotate
  618.     mov    di, offset point_buffer_1
  619.     mov     cx, NumPoints
  620.     
  621.     mov    [ds:lowest_z], 32767
  622.     mov    [ds:highest_z], -32768
  623.     
  624.     call    rotate_32
  625.  
  626. ;get ready to write to screen           
  627.     mov    ax, 0a000h
  628.     mov    es, ax
  629.  
  630. ;put v_wait in if your computer's too fast    
  631.     ;call    v_wait
  632. ;erase the old points    
  633.     call    erase
  634. ;fix up the highest_z(highest_z=higest_z-lowest_z)    
  635.     mov    ax, [ds:highest_z]
  636.     sub    ax, [ds:lowest_z]
  637.     and    ax, ax
  638.     jnz    @@15
  639. ;handle special case when highest_z=lowest_z(which doesn't happen
  640. ;at all in this version)
  641.     inc    ax
  642.     mov    [ds:lowest_z], -1
  643. @@15:
  644.     mov    [ds:highest_z], ax
  645. ;plot the new points        
  646.     mov    si, offset point_buffer_1
  647.     mov    cx, Numpoints
  648.     call    plot
  649.  
  650. ;print the numbers at bottom of screen
  651.     mov    ax, [ds:angle_1]
  652.     mov    di, 320*192+10
  653.     mov    dl, 66
  654.     call    print_number
  655.     
  656.     mov    ax, [ds:angle_2]
  657.     mov    di, 320*192+10+50
  658.     call    print_number
  659.     
  660.     mov    ax, [ds:angle_3]
  661.     mov    di, 320*192+10+100
  662.     call    print_number
  663.  
  664.     mov    ax, [ds:origon_x]
  665.     mov    di, 320*192+10+150
  666.     call    print_number
  667.  
  668.     mov    ax, [ds:origon_y]
  669.     mov    di, 320*192+10+200
  670.     call    print_number
  671.     
  672.     mov    ax, [ds:origon_z]
  673.     mov    di, 320*192+10+250
  674.     call    print_number
  675.     
  676.     mov    ax, [ds:frames_sec]
  677.     xor    di, di
  678.     call    print_number                
  679. ;check key    
  680. @@20:
  681.     mov     ah, 011h
  682.       int     16h
  683.         jnz     @@30
  684.     jmp     @@main_loop
  685. @@30:        
  686.     mov    ah, 010h
  687.     int    16h
  688. ;PLEASE IGNORE THE FOLLOWING CODE TO PROCESS EACH KEY: I WASN'T FEELING
  689. ;THAT WELL WHEN I MADE IT... I should of used a damn jump table!
  690.  
  691.     cmp     al, '4'
  692.     jne    @@k1
  693.     inc    [move_x]
  694.     jmp    @@main_loop
  695.     even
  696. @@k1:
  697.     cmp    al, '6'
  698.     jne    @@k2
  699.     dec     [ds:move_x]
  700.     jmp    @@main_loop
  701.     even
  702. @@k2:
  703.     cmp    al, '8'
  704.     jne    @@k3
  705.     inc    [ds:move_y]
  706.     jmp    @@main_loop
  707.     even
  708. @@k3:
  709.     cmp    al, '2'
  710.     jne    @@k4
  711.     dec    [ds:move_y]
  712.     jmp    @@main_loop
  713.     even
  714. @@k4:
  715.     cmp    al, '5'
  716.     jne    @@k5
  717.     xor    ax, ax
  718.     mov    [ds:move_x], ax
  719.     mov    [ds:move_y], ax
  720.     mov    [ds:move_z], ax
  721.     jmp    @@main_loop
  722.     even
  723. @@k5:
  724.     cmp    al, 'r'
  725.     jne    @@k4a
  726.     xor    ax, ax
  727.     mov    [ds:delta_1], ax
  728.     mov    [ds:delta_2], ax
  729.     mov    [ds:delta_3], ax
  730.     mov    [ds:angle_1], ax
  731.     mov    [ds:angle_2], ax
  732.     mov    [ds:angle_3], ax
  733.     jmp    @@main_loop
  734.     even
  735. @@k4a:    
  736.     cmp    al, ' '
  737.     jne    @@k5a
  738.     xor    ax, ax
  739.     mov    [ds:delta_1], ax
  740.     mov    [ds:delta_2], ax
  741.     mov    [ds:delta_3], ax
  742.     jmp    @@main_loop
  743.     even
  744. @@k5a:
  745.     cmp    al, 'm'
  746.     jne    @@k5b
  747.     inc    [ds:delta_2]
  748.     jmp    @@main_loop
  749.     even
  750. @@k5b:
  751.     cmp    al, 'n'
  752.     jne    @@k5c
  753.     dec    [ds:delta_2]
  754.     jmp    @@main_loop
  755.     even
  756. @@k5c:
  757.     cmp    al, '+'
  758.     jne    @@k6
  759.     dec    [ds:move_z]
  760.     jmp    @@main_loop
  761.     even
  762. @@k6:
  763.     cmp    al, '-'
  764.     jne    @@k7
  765.     inc    [ds:move_z]
  766.     jmp    @@main_loop
  767.     even
  768. @@k7:    
  769.     cmp    al, 27
  770.     je    @@exit
  771.     
  772.     cmp    ah, 72
  773.     jne    @@k9
  774.     inc    [ds:delta_1]
  775.     jmp    @@main_loop
  776.     even
  777. @@k9:
  778.     cmp     ah, 80
  779.     jne    @@k10
  780.     dec    [ds:delta_1]
  781.     jmp    @@main_loop
  782.     even
  783. @@k10:
  784.     cmp    ah, 75
  785.     jne    @@k11
  786.     dec    [ds:delta_3]
  787.     jmp    @@main_loop
  788.     even
  789. @@k11:
  790.     cmp    ah, 77
  791.     jne    @@k12
  792.     inc    [ds:delta_3]
  793.     jmp    @@main_loop
  794.     even
  795. @@k12:
  796.     jmp    @@main_loop    
  797. @@exit:
  798.     mov    ax, 00003h
  799.         int    10h
  800.         mov    ah, 4Ch
  801.         int    21h
  802. ;-------------------------------------------------------------------------------
  803. ;rotation routine
  804.     even
  805. proc     rotate_32
  806.     mov    [ds:points_left], cx
  807.     mov    [ds:source], si
  808.     mov    [ds:dest], di
  809.     
  810.     even
  811. @@10:
  812.  
  813. ;copy the current points to rotate to a work area
  814.        
  815.     mov    si, [ds:source]
  816.     mov    di, offset Xo
  817.     mov    cx, 3
  818.     rep    movsw
  819.     mov    [ds:source], si
  820. ;do first calculation:
  821. ;X1 = (Xo * C1 - Yo * S1) \ 16384
  822.  
  823.     mov    bp, [ds:sin_1]
  824.     mov    bx, [ds:cos_1]
  825.  
  826.     mov    ax, [ds:yo]
  827.     imul    bp            ;Yo*S1
  828.     mov    si, ax
  829.     mov    di, dx
  830.     
  831.     mov    ax, [ds:xo]
  832.     imul    bx            ;Xo*C1
  833.     sub    ax, si
  834.     sbb    dx, di
  835.     
  836.     
  837.     sal    ax, 1
  838.     rcl    dx, 1
  839.     sal    ax, 1
  840.     rcl    dx, 1
  841.     
  842.     mov    cx, dx
  843.  
  844. ;now do Y1 = (Xo * S1 + Yo * C1) \ 16384
  845.  
  846.     mov    ax, [ds:xo]
  847.     imul    bp            ;Xo*S1
  848.     mov    si, ax
  849.     mov    di, dx
  850.     
  851.     mov    ax, [ds:yo]
  852.     imul    bx            ;Yo*C1
  853.     add    ax, si
  854.     adc    dx, di
  855.             
  856.     sal    ax, 1
  857.     rcl    dx, 1
  858.     sal    ax, 1
  859.     rcl    dx, 1
  860.  
  861.     mov    [ds:y1], dx
  862.  
  863. ;second vector
  864. ;X2 = (X1 * C2 - Zo * S2) \ 16384 - Mx + Ox
  865.  
  866.     mov    bp, [ds:sin_2]
  867.     mov    bx, [ds:cos_2]
  868.  
  869.     mov    ax, [ds:zo]
  870.     imul    bp
  871.     mov    si, ax
  872.     mov    di, dx
  873.  
  874.     mov    ax, bx
  875.     imul    cx            ;X1*c2
  876.     sub    ax, si
  877.     sbb    dx, di
  878.     
  879.     sal    ax, 1
  880.     rcl    dx, 1
  881.     sal    ax, 1
  882.     rcl    dx, 1
  883.  
  884.     add    dx, [ds:origon_x]
  885.     mov     [ds:x2], dx
  886.  
  887. ;Z2 = (X1 * S2 + Zo * C2) \ 16384
  888.     
  889.     mov    ax, bp
  890.     imul    cx            ;X1*S2
  891.     mov    si, ax
  892.     mov    di, dx
  893.     
  894.  
  895.     mov    ax, [ds:zo]
  896.     imul    bx            ;Zo*C2
  897.     add    ax, si
  898.     adc    dx, di
  899.             
  900.     sal    ax, 1
  901.     rcl    dx, 1
  902.     sal    ax, 1
  903.     rcl    dx, 1
  904.  
  905.     mov    cx, dx
  906.     
  907. ;third vector
  908. ;Y3 = (Y1 * C3 - Z2 * S3) \ 16384 - My + Oy
  909.  
  910.     mov    bp, [ds:sin_3]
  911.     mov    bx, [ds:cos_3]
  912.     
  913.     mov    ax, bp
  914.     imul    cx            ;Z2*S3
  915.     mov    si, ax
  916.     mov    di, dx
  917.  
  918.     
  919.     mov    ax, bx
  920.     imul    [ds:y1]            ;Y1*C3
  921.     sub    ax, si
  922.     sbb    dx, di
  923.     
  924.     sal    ax, 1
  925.     rcl    dx, 1
  926.     sal    ax, 1
  927.     rcl    dx, 1
  928.  
  929.     add    dx, [ds:origon_y]
  930.     mov    [ds:y3], dx
  931.  
  932. ;Z4 = (Y1 * S3 + Z2 * C3) \ 16384
  933.     
  934.     mov    ax, bp
  935.     imul    [ds:y1]            ;Y1*S3
  936.     mov    si, ax
  937.     mov    di, dx
  938.         
  939.     mov    ax, bx
  940.     imul    cx            ;Z2*C3
  941.     add    ax, si
  942.     adc    dx, di
  943.     
  944.     sal    ax, 1
  945.     rcl    dx, 1
  946.     sal    ax, 1
  947.     rcl    dx, 1
  948.  
  949.     mov    di, [ds:dest]
  950.  
  951. ;save the z coordinate in the output table    
  952.     mov     [ds:di+4], dx
  953.  
  954. ;check to see if lowest or highest z
  955.     cmp    dx, [ds:lowest_z]
  956.     jnl    @@notlower
  957.     mov    [ds:lowest_z], dx
  958. @@notlower:
  959.     cmp    dx, [ds:highest_z]
  960.     jng    @@notgreater
  961.     mov    [ds:highest_z], dx
  962. @@notgreater:
  963.     add    dx, [ds:origon_z]
  964.  
  965. ;now do V=(Spos-Z)/(Mpos-Z)
  966.     
  967.     neg    dx
  968.     mov     bx, dx
  969.     add    bx, [ds:m_pos]
  970. ;is the point in view?
  971.     cmp    bx, Z_Plane_Threshold
  972.     jg    @@in_view
  973. ;nope    
  974.     mov    ax, -32768
  975.     mov    cx, 3
  976.     rep    stosw
  977.     mov    [ds:dest], di
  978.     jmp     @@next_point
  979.     even
  980. @@in_view:
  981. ;V= (p_scaler*(Spos-Z)) / (Mpos-Z)
  982.  
  983.     add    dx, [ds:s_pos]
  984.     mov    ax, dx
  985.     mov    cx, P_Scaler
  986.     imul    cx
  987.     
  988.     idiv    bx
  989.     neg    ax
  990.  
  991. ;x=160+x2+(x2*-v)\p_scaler
  992. ;(or really x=160+x2+(-x2*v)\p_scaler )        
  993.     mov    bx, ax
  994.     mov    bp, [ds:x2]
  995.     mov    ax, bp
  996.     imul    bx        ;x2 * v
  997.     idiv    cx
  998.     add    ax, bp
  999.     add    ax, 160
  1000.     stosw
  1001. ;y=100+y2+(y2*-v)\p_scaler
  1002.     mov    bp, [ds:y3]
  1003.     mov    ax, bp
  1004.     imul    bx
  1005.     idiv    cx
  1006.     add    ax, bp
  1007.     add    ax, 100
  1008.     stosw
  1009. ;skip by the already stored Z coordinate    
  1010.     inc     di
  1011.     inc     di
  1012.     mov    [ds:dest], di
  1013.     
  1014. @@next_point:
  1015.     
  1016.     dec        [ds:points_left]
  1017.     jz    @@20
  1018.     jmp    @@10
  1019.     even
  1020. @@20:
  1021.     ret
  1022. endp     rotate_32
  1023. ;-------------------------------------------------------------------------------
  1024.     even
  1025. ;plots the points to the 320x200x256 screen
  1026. proc     plot
  1027.     mov    [ds:point_loc], offset point_buffer_2
  1028.     even    
  1029. @@10:
  1030.     lodsw
  1031.     and     ax, ax
  1032.     jl     @@not_in_view_1
  1033.     cmp    ax, 319
  1034.     jg    @@not_in_view_1
  1035.     mov    di, ax
  1036.     lodsw
  1037.     and     ax, ax
  1038.     jl    @@not_in_view_2
  1039.     cmp    ax, 190
  1040.     jg    @@not_in_view_2
  1041.     mov    bx, ax
  1042.     add    bx, bx
  1043.     add    di, [word ds:line_table+bx]
  1044.  
  1045. ;color_of_point = 10 + ( 53*(Z-Lowest_Z) ) / Highest_Z    
  1046. ;where color 10 is dark and color 63 is bright
  1047.  
  1048.     lodsw
  1049.     sub    ax, [ds:lowest_z]
  1050.     mov    bp, 53
  1051.     imul    bp
  1052.     idiv    [ds:highest_z]
  1053.     add    al, 10
  1054.     
  1055.     mov    bx, [ds:point_loc]
  1056.     mov    [ds:bx], di
  1057.     inc    bx
  1058.     inc    bx
  1059.     mov    [ds:point_loc], bx
  1060.     
  1061.     stosb
  1062.     
  1063.     loop     @@10
  1064.     ret
  1065.     even
  1066. @@not_in_view_1:
  1067.     add    si, 4
  1068.     loop    @@10
  1069.     ret
  1070.     even
  1071. @@not_in_view_2:
  1072.     inc    si
  1073.     inc    si
  1074.     loop    @@10
  1075.     ret
  1076. endp    plot
  1077. ;-------------------------------------------------------------------------------
  1078.     even
  1079. ;erases points last set
  1080. proc     erase
  1081.     xor     bl, bl
  1082.     mov    dx, [ds:point_loc]
  1083.     mov    si, offset point_buffer_2
  1084.     cmp    si, dx
  1085.     je    @@exit
  1086.     even
  1087. @@10:
  1088.     rept    8
  1089.     lodsw
  1090.     mov    di, ax
  1091.     mov    al, bl
  1092.     stosb
  1093.     cmp    si, dx
  1094.     je    @@exit
  1095.     endm
  1096.     lodsw
  1097.     mov    di, ax
  1098.     mov    al, bl
  1099.     stosb
  1100.     cmp    si, dx
  1101.     jne    @@10
  1102. @@exit:
  1103.     
  1104.     ret
  1105. endp    erase
  1106. ;-------------------------------------------------------------------------------
  1107.     even
  1108. ;waits for vertical retrace
  1109. proc    v_wait
  1110.     mov    dx, 03dah
  1111.     mov    ah, 8
  1112.  
  1113. @@10:
  1114.     in    al, dx
  1115.     and    al, ah
  1116.     jnz     @@10
  1117.     
  1118.     even
  1119. @@20:
  1120.     in    al, dx
  1121.     and    al, ah
  1122.     jz     @@20
  1123.     ret
  1124. endp     v_wait
  1125. ;-------------------------------------------------------------------------------
  1126.     even
  1127. ;sets up cosine and sign of each angle
  1128. ;sine(A)=sine(A)
  1129. ;cosine(A)=sine(A+90)
  1130. proc    set_angles
  1131.     mov    bx, [ds:angle_1]
  1132.     add    bx, bx
  1133.     mov    ax, [word ds:sine_table+bx]
  1134.     mov    [ds:sin_1], ax
  1135.     mov    ax, [word ds:sine_table+bx+90*2]
  1136.     mov    [ds:cos_1], ax
  1137.  
  1138.     mov    bx, [ds:angle_2]
  1139.     add    bx, bx
  1140.     mov    ax, [word ds:sine_table+bx]
  1141.     mov    [ds:sin_2], ax
  1142.     mov    ax, [word ds:sine_table+bx+90*2]
  1143.     mov    [ds:cos_2], ax
  1144.         
  1145.     mov    bx, [ds:angle_3]
  1146.     add    bx, bx
  1147.     mov    ax, [word ds:sine_table+bx]
  1148.     mov    [ds:sin_3], ax
  1149.     mov    ax, [word ds:sine_table+bx+90*2]
  1150.     mov    [ds:cos_3], ax
  1151.     ret
  1152. endp     set_angles            
  1153. ;-------------------------------------------------------------------------------
  1154.     even
  1155. ;sets up the blue palette
  1156. proc    set_palette
  1157.     mov    dx, 03c7h
  1158.     mov    cx, 64
  1159.     xor    ax, ax
  1160.     even
  1161. @@10:
  1162.     out     dx, al
  1163.     inc    dx
  1164.     out    dx, al
  1165.     inc    dx
  1166.     
  1167.     xchg    al, ah
  1168.     out    dx, al
  1169.     out    dx, al
  1170.     xchg    al, ah
  1171.     out    dx, al
  1172.         
  1173.     dec    dx
  1174.     dec    dx
  1175.     inc    ax
  1176.     loop    @@10
  1177.     
  1178.     ret
  1179. endp    set_palette
  1180. ;-------------------------------------------------------------------------------
  1181.     even
  1182. ;takes a binary number in ax and turns it into a series of digits
  1183. proc    make_number
  1184.     and    ax, ax
  1185.     jnl    @@00
  1186.     neg    ax
  1187.     mov    [ds:number_buffer], offset minus_sign
  1188.     jmp    short @@01
  1189.     even
  1190. @@00:
  1191.     mov    [ds:number_buffer], offset space
  1192. @@01:
  1193.     mov    bp, 10
  1194.     xor    bx, bx
  1195.     mov    cx, offset characters
  1196.         
  1197.     std
  1198.     mov    di, offset number_buffer+10
  1199.     
  1200.     rept    5
  1201.     mov    dx, bx
  1202.     div    bp
  1203.     xchg    ax, dx
  1204.     shl    ax, 1
  1205.     shl    ax, 1
  1206.     shl    ax, 1
  1207.     add    ax, cx
  1208.     stosw
  1209.     xchg    ax, dx
  1210.     endm
  1211.     
  1212.     cld
  1213.     
  1214.     ret
  1215. endp     make_number
  1216. ;-------------------------------------------------------------------------------
  1217.     even
  1218. proc    write_number
  1219.     
  1220.     mov    cx, 6
  1221.     push    offset number_buffer
  1222.     even
  1223. @@10:
  1224.     pop     si
  1225.     lodsw
  1226.     push     si
  1227.     mov    si, ax
  1228.     push    cx
  1229.     push     di
  1230.     call    write_char
  1231.     pop    di
  1232.     pop    cx
  1233.     add    di, 7
  1234.     loop    @@10
  1235.     pop    ax
  1236.     ret
  1237. endp     write_number
  1238. ;-------------------------------------------------------------------------------
  1239.     even
  1240. ;writes a bit-mapped font to screen
  1241. proc    write_char
  1242.     mov    bp, 320-5
  1243.     mov    cx, 7
  1244.     even
  1245. @@10:
  1246.     lodsb
  1247.     mov    bl, al
  1248.     mov    al, ch
  1249.  
  1250.     shl    bl, 1
  1251.     jc    @@write_1
  1252.     stosb
  1253. @@e1:
  1254.     shl    bl, 1
  1255.     jc    @@write_2
  1256.     stosb
  1257. @@e2:
  1258.     shl    bl, 1
  1259.     jc    @@write_3
  1260.     stosb
  1261. @@e3:
  1262.     shl    bl, 1
  1263.     jc    @@write_4
  1264.     stosb
  1265. @@e4:
  1266.     shl    bl, 1
  1267.     jc    @@write_5
  1268.     stosb
  1269. @@e5:
  1270.     add    di, bp
  1271.     loop    @@10
  1272.         
  1273.     ret
  1274.     even
  1275. @@write_1:
  1276.     xchg    al, dl
  1277.     stosb
  1278.     xchg    al, dl
  1279.     jmp    short @@e1
  1280.     even
  1281. @@write_2:
  1282.     xchg    al, dl
  1283.     stosb
  1284.     xchg    al, dl
  1285.     jmp    short @@e2
  1286.     even
  1287. @@write_3:
  1288.     xchg    al, dl
  1289.     stosb
  1290.     xchg    al, dl
  1291.     jmp    short @@e3
  1292.     even
  1293. @@write_4:
  1294.     xchg    al, dl
  1295.     stosb
  1296.     xchg    al, dl
  1297.     jmp    short @@e4
  1298.     even
  1299. @@write_5:
  1300.     xchg    al, dl
  1301.     stosb
  1302.     xchg    al, dl
  1303.     jmp    short @@e5
  1304.     even
  1305. endp    write_char
  1306. ;-------------------------------------------------------------------------------
  1307.     even
  1308. ;prints a number to the screen
  1309. proc    print_number
  1310.     mov     bx, @data
  1311.     mov    es, bx
  1312.     
  1313.     push    dx
  1314.     push    di
  1315.     call    make_number
  1316.     pop    di
  1317.     pop    dx
  1318.         
  1319.     mov    ax, 0a000h
  1320.     mov    es, ax
  1321.     
  1322.     call    write_number
  1323.  
  1324.     ret
  1325. endp    print_number
  1326. ;-------------------------------------------------------------------------------
  1327. even
  1328. ;prints a asciz string to the screen
  1329. proc    print_string
  1330.     push    dx
  1331.     mov    al, bl
  1332.     mov    dl, 7
  1333.     mul    dl
  1334.     mov    di, ax
  1335.     
  1336.     mov    al, bh
  1337.     xor    ah, ah
  1338.     mov    bx, 320*8
  1339.     mul    bx
  1340.     add    di, ax
  1341.     pop    dx
  1342.         
  1343.     push     si
  1344.     even
  1345. @@10:
  1346.     pop     si
  1347.     lodsb
  1348.     push    si
  1349.     and    al, al
  1350.     jz     @@exit
  1351.     
  1352.     sub    al, 'A'
  1353.     js    @@space
  1354.     xor    ah, ah
  1355.     shl    ax, 1
  1356.     shl    ax, 1
  1357.     shl    ax, 1
  1358.     add    ax, offset letters
  1359.     mov    si, ax
  1360. @@cont:
  1361.     push    di
  1362.     call    write_char
  1363.     pop    di
  1364.     
  1365.     add    di, 7
  1366.     jmp     @@10    
  1367.     even
  1368. @@exit:
  1369.     pop    si
  1370.     
  1371.     ret
  1372.     even
  1373. @@space:
  1374.     cmp    al, '0'-'A'
  1375.     jl    @@n1
  1376.     cmp    al, '9'-'A'
  1377.     jg    @@n1
  1378.     add    al, 'A'-'0'
  1379.     xor    ah, ah
  1380.     shl    ax, 1
  1381.     shl    ax, 1
  1382.     shl    ax, 1
  1383.     add    ax, offset characters
  1384.     mov    si, ax
  1385.     jmp    short @@cont
  1386.     even
  1387. @@n1:
  1388.     cmp    al, '-'-'A'
  1389.     jne    @@n2
  1390.     mov    si, offset minus_sign
  1391.     jmp    short @@cont
  1392.     even
  1393. @@n2:
  1394.     mov     si, offset space
  1395.     jmp     short @@cont
  1396. endp     print_string
  1397. even
  1398. ;my stupid title...
  1399. proc    print_title
  1400.     mov    ax, 0a000h
  1401.     mov    es, ax
  1402.     
  1403.     mov    dx, 03c7h
  1404.     mov    al, 65
  1405.     out    dx, al
  1406.     inc    dx
  1407.     out    dx, al
  1408.     inc    dx
  1409.     xor    al, al
  1410.     rept    3
  1411.     out    dx, al
  1412.     endm
  1413.         
  1414.     mov    si, offset string_1
  1415.     mov    cx, 8
  1416.     mov    dl, 65
  1417. @@1:
  1418.     lodsw
  1419.     mov    bx, ax
  1420.     push    cx
  1421.     call    print_string
  1422.     pop    cx
  1423.     loop    @@1
  1424.     mov    cx, 0100h
  1425.     even    
  1426. @@2:
  1427.     call    v_wait
  1428.     mov    dx, 03c7h
  1429.     mov    al, 65
  1430.     out    dx, al
  1431.     inc    dx
  1432.     out    dx, al
  1433.     inc    dx
  1434.     
  1435.     xor    al, al
  1436.     out    dx, al
  1437.     out    dx, al
  1438.     mov    al, cl
  1439.     out    dx, al
  1440.  
  1441.     call    v_wait
  1442.     
  1443.     mov    dx, 03c7h
  1444.     mov    al, 65
  1445.     out    dx, al
  1446.     inc    dx
  1447.     out    dx, al
  1448.     inc    dx
  1449.     mov    al, 63
  1450.     out    dx, al
  1451.     xor    al, al
  1452.     out    dx, al
  1453.     out    dx, al
  1454.  
  1455.         
  1456.         add    cl, ch
  1457.         cmp    cl, 64
  1458.     jne    @@20
  1459.     mov     ah, 011h
  1460.       int     16h
  1461.         jnz     @@30
  1462.     neg    ch
  1463.     add    cl, ch
  1464.     even
  1465. @@20:        
  1466.     and    cl, cl
  1467.     jnl    @@2
  1468.     neg    ch
  1469.     add    cl, ch
  1470.     jmp    short @@2
  1471.     even
  1472. @@30:
  1473.     mov     ah, 010h
  1474.       int     16h
  1475.     
  1476.     mov    cx, 32000
  1477.     xor    ax, ax
  1478.     mov    di, ax
  1479.     rep    stosw
  1480.  
  1481.     ret
  1482. endp     print_title
  1483. ;that's all have fun
  1484. end
  1485.         
  1486.